package com.test.daily.leetcode.y2022.m07.day0720.v20;

import java.util.*;

/**
 * @author Tom on 2022/7/20
 */
public class Solution {
    public List<List<Integer>> shiftGrid(int[][] grid, int k) {
        int row = grid.length;
        int col = grid[0].length;
        List<List<Integer>> ans = new ArrayList<>();
        for (int i = 0; i < row; i++) {
            List<Integer> l = new ArrayList<>();
            for (int j = 0; j < col; j++) {
              l.add(0);
            }
            ans.add(l);
        }
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                int index1 = (i * col + j + k) % (row*col);
                ans.get(index1/col).set(index1%col, grid[i][j]);
            }
        }
        return ans;
    }
}
